package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.user.UserBehavior;
import lombok.SneakyThrows;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;

/***
 * 模拟用户行为测试接口
 */
@RestController
@RequestMapping("/api/user/test")
public class UserTestController {

    @Autowired
    private RabbitTemplate rabbitTemplate;
//    @Autowired
//    private KafkaTemplate kafkaTemplate;

    /**
     * 模拟用户行为
     * @return
     */
    @SneakyThrows
    @GetMapping
    public Result test(){
//        UserBehavior userBehavior = new UserBehavior();
//        userBehavior.setAlbumId(1L);
//        for (int i = 1; i <= 100000 ; i++) {
//            switch (i%5){
//                case 0 -> userBehavior.setBehaviorType(UserBehavior.BehaviorType.PLAY);
//                case 1 -> userBehavior.setBehaviorType(UserBehavior.BehaviorType.BUY);
//                case 2 -> userBehavior.setBehaviorType(UserBehavior.BehaviorType.COLLECT);
//                case 3 -> userBehavior.setBehaviorType(UserBehavior.BehaviorType.COMMENT);
//                case 4 -> userBehavior.setBehaviorType(UserBehavior.BehaviorType.SUBSCRIBE);
//            }
//        }
//        CompletableFuture completableFuture = kafkaTemplate.send("a", "");
//        completableFuture.get(); // 异步 有返回值
//        rabbitTemplate.convertAndSend("","",""); // 同步 无返回值

//        for (int i = 1; i <= 10; i++) {
//            kafkaTemplate.send("c","mess"+i);
//        }
//        for (int i = 1; i <= 5; i++) {
//            kafkaTemplate.send("b",i,"指定分片");
//        }
//        for (int i = 1; i <= 5; i++) {
//            kafkaTemplate.send("b",i,"key","指定分片和key"+i);
//        }
        return Result.ok();
    }

}
